//
//  MSPersonalEditorController.m
//  觅尚
//
//  Created by No.8 on 2019/4/29.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSPersonalEditorController.h"
#import <BRPickerView.h>
#import "BRTextField.h"
#import "NSDate+BRAdd.h"
#import "MSPrensetView.h"
#import "HMDatePickView.h"
#import "HQPickerView.h"
#import "GFAddressPicker.h"
#import "MSCompanyController.h"
#import "zySheetPickerView.h"
#import "FYLCityPickView.h"

@interface MSPersonalEditorController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate,HQPickerViewDelegate,GFAddressPickerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
//通用导航栏
{
    CustomNavigationBar *naviagtionBar;
    
}

@property (nonatomic, strong) GFAddressPicker *pickerView;
/** 表头*/
@property(nonatomic,strong)MSPrensetView *PrensetView;

@property (nonatomic, strong) UITableView *tableView;


@property (nonatomic, strong) NSArray *titleArr;

/** 性别*/
@property (nonatomic, strong) NSArray *sexArray;


/** 性别图片*/
@property (nonatomic, strong) NSArray *sexIMGArray;



@property (copy, nonatomic) NSString *dateStr;

/** 选择生日按钮*/
@property(nonatomic,strong)UIButton * birthdayButton;


/** 国家*/
@property(nonatomic,strong)UIButton * stateButton;

/** 身高*/
@property(nonatomic,strong)UITextField *statureTextField;

/** 头像*/
@property(nonatomic,strong)UIImageView *photoImg;


/** 分割线*/
@property(nonatomic,strong)UIImageView *FengeImg;


/** 姓名*/
@property(nonatomic,strong)UITextField *NameTextField;


/** 性别选择*/
@property(nonatomic,strong)UIButton *SexSelectedButton;


/** 籍贯选择*/
@property(nonatomic,strong)UIButton *AddressButton;


/** 身高*/
@property(nonatomic,strong)UITextView *SpecialityText;



/** 特长*/
@property(nonatomic,strong)UITextView *SpecialityTextView;


/** 选择按钮*/
@property(nonatomic,strong)UIButton *selectedButton;


/** 性别*/
//@property(nonatomic,strong)NSString *gender;

/** 爱好*/
@property(nonatomic,strong)NSString *specialityStr;

/** URL*/
@property(nonatomic,strong)NSString *URLStr;


@end

@implementation MSPersonalEditorController
/** Nav实现 */
- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
//- (void)MJChiBaoZiHeaderRefresh{
//    [self ReloadData];
//}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self sexArray];
    
    [self AddLoginView];
    
    [self AnimationClick];
    
    [self createNavigationBar];
    
}
//添加界面
- (void)AddLoginView{
    
    [self NameTextField];
    
    [self photoImg];
    
    [self birthdayButton];
    
    [self statureTextField];
    
    [self AddressButton];
    
    [self FengeImg];
    
    [self SpecialityText];
    
    [self CreatFootView];
    
}

- (void)CreatFootView{
    
    UIView * FootView = [[UIView alloc] initWithFrame:CGRectMake( 0, 0, ScreenWidth, 600 * px)];
    [self.view addSubview:FootView];
    
    
    
    UIView * linView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FootView.width, 1)];
    linView.backgroundColor = [UIColor darkGrayColor];
    [FootView addSubview:linView];
    
    
    /** 特长*/
    UILabel * SpecialityLabel = [[UILabel alloc] initWithFrame:CGRectMake(50 * px, 60 * px, 200 * px, 60 * px)];
    SpecialityLabel.textColor = [UIColor whiteColor];
    SpecialityLabel.text = @"特长(选填)";
    SpecialityLabel.textAlignment = NSTextAlignmentLeft;
    SpecialityLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    [FootView addSubview:SpecialityLabel];
    
    UIView * ForView = [[UIView alloc] initWithFrame:CGRectMake(SpecialityLabel.x, CGRectGetMaxY(SpecialityLabel.frame) + 20 * px, FootView.width, 100 * px)];
    ForView.backgroundColor = [UIColor clearColor];
    [FootView addSubview:ForView];
    
    
    NSArray * titleArray = @[@"歌曲",@"舞蹈",@"外语",@"其他"];
    CGFloat titleButtonW = (FootView.width - 250 * px) / titleArray.count;
    CGFloat titleButtonY = 0;
    CGFloat titleButtonH = ForView.height;
    
    for (int i = 0; i < titleArray.count; i ++) {
        /** 按钮*/
        UIButton * titleButton = [[UIButton alloc] initWithFrame:CGRectMake((titleButtonW + 50 * px) * i, titleButtonY, titleButtonW, titleButtonH)];
        [titleButton setTitle:titleArray[i] forState:UIControlStateNormal];
        titleButton.tag = i + 200;
        titleButton.layer.borderColor = [UIColor darkGrayColor].CGColor;//设置边框颜色
        titleButton.layer.borderWidth = 1.0f;//设置边框颜色
        [titleButton setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
        [titleButton setBackgroundImage:[UIImage imageWithColor:FontColor] forState:UIControlStateDisabled];
        titleButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [titleButton  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [titleButton  addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [ForView  addSubview:titleButton];
        if (i == 0) {
            [self titleButtonClick:titleButton];
            titleButton.enabled = NO;
            self.selectedButton = titleButton;
            
        }
    }
    
    
    /** 确定*/
    UIButton * confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(100 * px, CGRectGetMaxY(ForView.frame) + 80 * px, ScreenWidth - 200 * px, 120 * px)];
    [confirmButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    confirmButton.layer.cornerRadius = 60 * px;
    confirmButton.layer.masksToBounds = YES;
    [confirmButton setTitle:@"确认修改" forState:UIControlStateNormal];
    confirmButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(32 / 2)];
    [confirmButton  setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton  addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [FootView  addSubview:confirmButton];
    
    self.tableView.tableFooterView = FootView;
}
- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

- (void)titleButtonClick:(UIButton *)sender{
    WYCLog(@"---------------%ld",(long)sender.tag);
    
    self.selectedButton.enabled = YES;
    sender.enabled = NO;
    self.selectedButton = sender;
}
//添加点击事件
- (void)AnimationClick{
    
    [self.PrensetView.backButton addTarget:self action:@selector(AnimationbackButton) forControlEvents:UIControlEventTouchUpInside];
    
    [self.PrensetView.stepButton addTarget:self action:@selector(AnimationstepButton) forControlEvents:UIControlEventTouchUpInside];
    
    
}

//确认修改
- (void)confirmButtonClick{
    NSString *NameTextStr = [_NameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString * statureTextStr = [_statureTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if (NameTextStr.length == 0) {
        [MBManager showBriefAlert:@"姓名不能为空"];
        return;
    }
    if (_photoImg.image == [UIImage imageNamed:@"上传头像"]) {
        [MBManager showBriefAlert:@"头像不能为空"];
        return;
    }
    if (statureTextStr.length == 0){
        [MBManager showBriefAlert:@"身高不能为空"];
        return;
    }
    if ([_birthdayButton.titleLabel.text isEqualToString:@"请选择"]) {
        [MBManager showBriefAlert:@"生日不能为空"];
        return;
    }
    if ([_stateButton.titleLabel.text isEqualToString:@"请选择"]) {
        [MBManager showBriefAlert:@"国籍不能为空"];
        return;
    }
    if ([_AddressButton.titleLabel.text isEqualToString:@"请选择"]) {
        [MBManager showBriefAlert:@"籍贯不能为空"];
        return;
    }
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    if (self.SexSelectedButton.tag == 0) {
//        self.gender = @"1";
        params[@"gender"] = @"1";
    }else{
        params[@"gender"] = @"0";
    }
    if (self.selectedButton.tag == 200) {
        params[@"speciality"]  = @"1";
    }else if (self.selectedButton.tag == 201){
        params[@"speciality"] = @"2";
    }else if (self.selectedButton.tag == 202){
        params[@"speciality"] = @"3";
    }else{
        params[@"speciality"] = @"4";
    }
    
    if (self.URLStr.length != 0) {
        params[@"avatarUrl"] = self.URLStr;
    }else{
        params[@"avatarUrl"] = [NSString stringWithFormat:@"%@",[WYCAccountTool unarchiveavatarUrl]];
    }
    params[@"birthday"] = self.birthdayButton.titleLabel.text;
    params[@"userName"] = self.NameTextField.text;
    params[@"province"] = _AddressButton.titleLabel.text;
    params[@"country"] = self.stateButton.titleLabel.text;
    params[@"height"] = _statureTextField.text;
    params[@"uid"] = [WYCAccountTool unarchiveuid];
    
    
    [HTTPRequest POST:MSupdateUserInfo params:params succeed:^(id responseObject) {
        if (CodeStr) {
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }else{
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }
    } failure:^(NSError *error) {
        [MBManager showBriefAlert:Failed];
//        WYCLog(@"error----------%@",error);
    }];
    
   
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, ScreenHeight - [self navBarBottom]) style:UITableViewStylePlain];
        //        _tableView.backgroundColor = [UIColor clearColor];
        UIImageView *backImageView=[[UIImageView alloc]initWithFrame:self.view.bounds];
        [backImageView setImage:[UIImage imageNamed:@"完善信息bg"]];
        self.tableView.backgroundView = backImageView;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        //        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _tableView.separatorColor = [UIColor darkGrayColor];
        _tableView.tableFooterView = [[UIView alloc]init];
        [self.view addSubview:_tableView];
    }
    return _tableView;
}
#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 150 * px;
    }else{
        return 250 * px;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"testCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.text = [self.titleArr objectAtIndex:indexPath.row];
    
    switch (indexPath.row) {
        case 0:
        {
            [cell.contentView addSubview:_NameTextField];
            //            [cell.contentView addSubview:_FengeImg];
            
        }
            break;
        case 1:
        {
            [cell.contentView addSubview:_photoImg];
            //            [cell.contentView addSubview:_FengeImg];
        }
            break;
        case 2:
        {
            //            [cell.contentView addSubview:_FengeImg];
            CGFloat width = 300 * px;
            CGFloat height = 100 * px;
            for (NSInteger i = 0; i < _sexArray.count; i ++) {
                UIButton *Sexbutton = [[UIButton alloc] init];
                Sexbutton.tag = i;
                Sexbutton.height = height;
                Sexbutton.width = width;
                Sexbutton.x = i * (width + 100 * px) + ScreenWidth * 0.3;
                Sexbutton.y = 100 * px;
                [Sexbutton setTitle:_sexArray[i] forState:UIControlStateNormal];
                [Sexbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                //                Sexbutton.backgroundColor = [UIColor redColor];
                [Sexbutton setBackgroundImage:[UIImage imageNamed:@"sex_nomor_icon"] forState:UIControlStateNormal];
                
                [Sexbutton setBackgroundImage:[UIImage imageNamed:@"sex_select_icon"] forState:UIControlStateDisabled];
                [Sexbutton layoutIfNeeded];//强制布局
                Sexbutton.titleLabel.textAlignment = NSTextAlignmentCenter;
                Sexbutton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
                [Sexbutton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:Sexbutton];
                WYCLog(@"======%@",[WYCAccountTool unarchivegender]);
                if ([self.gender intValue] == 1) {
                    if (i == 0) {
                        [self titleClick:Sexbutton];
                        Sexbutton.enabled = NO;
                        
                        self.SexSelectedButton = Sexbutton;
                    }
                }else{
                    if (i == 1) {
                        [self titleClick:Sexbutton];
                        Sexbutton.enabled = NO;
                        
                        self.SexSelectedButton = Sexbutton;
                    }
                }
                // 默认点击了第一个按钮
                
            }
        }
            break;
        case 3:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            [cell.contentView addSubview:_statureTextField];
        }
            break;
        case 4:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            [cell.contentView addSubview:_birthdayButton];
        }
            break;
        case 5:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
            UIButton *stateButton = [[UIButton alloc] init];
            stateButton.frame = CGRectMake(ScreenWidth * 0.5, 95 * px, ScreenWidth * 0.5 - 100 * px, 60 * px);
            [stateButton setTitle:[NSString stringWithFormat:@"%@",[WYCAccountTool unarchivecountry]] forState:UIControlStateNormal];
            [stateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            stateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
            stateButton.titleLabel.font = _birthdayButton.titleLabel.font;
            [stateButton addTarget:self action:@selector(showPickerView) forControlEvents:UIControlEventTouchUpInside];
            
            [cell.contentView addSubview:stateButton];
            self.stateButton = stateButton;
        }
            break;
        case 6:
        {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            [cell.contentView addSubview:_AddressButton];
        }
            break;
            
            
    }
    
    return cell;
}
- (void)titleClick:(UIButton *)button
{
    //修改按钮状态
    self.SexSelectedButton.enabled = YES;
    button.enabled = NO;
    self.SexSelectedButton = button;
    
}

//选择生日
- (void)birthdayButtonClick{
    HMDatePickView *datePickVC = [[HMDatePickView alloc] initWithFrame:self.view.frame];
    //距离当前日期的年份差（设置最大可选日期）
    datePickVC.maxYear = -1;
    //设置最小可选日期(年分差)
    //    _datePickVC.minYear = 10;
    datePickVC.date = [NSDate date];
    //设置字体颜色
    datePickVC.fontColor = [UIColor redColor];
    //日期回调
    datePickVC.completeBlock = ^(NSString *selectDate) {
        [self.birthdayButton setTitle:selectDate forState:UIControlStateNormal];
    };
    //配置属性
    [datePickVC configuration];
    
    [self.view addSubview:datePickVC];
    
}
/** 姓名输入*/
- (UITextField *)statureTextField {
    if (!_statureTextField) {
        _statureTextField = [[UITextField alloc] init];
        _statureTextField.frame = CGRectMake(ScreenWidth - 600 * px, 75* px, 500 * px, 100 * px);
//        _statureTextField.placeholder = @"请输入身高CM";
        _statureTextField.text = [NSString stringWithFormat:@"%@",[WYCAccountTool unarchiveheight]];
        _statureTextField.keyboardType = UIKeyboardTypeNumberPad;
        [_statureTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [_statureTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
        _statureTextField.textColor = [UIColor whiteColor];
        _statureTextField.textAlignment = NSTextAlignmentRight;
    }
    return _statureTextField;
}
/** 生日选择*/
- (UIButton *)birthdayButton {
    if (!_birthdayButton) {
        _birthdayButton = [[UIButton alloc] init];
        _birthdayButton.frame = CGRectMake(ScreenWidth * 0.5, 95 * px, ScreenWidth * 0.5 - 100 * px, 60 * px);
        [_birthdayButton setTitle:[NSString stringWithFormat:@"%@",[WYCAccountTool unarchivebirthday]] forState:UIControlStateNormal];
        [_birthdayButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _birthdayButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _birthdayButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        [_birthdayButton addTarget:self action:@selector(birthdayButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _birthdayButton;
}


/** 籍贯选择*/
- (UIButton *)AddressButton {
    if (!_AddressButton) {
        _AddressButton = [[UIButton alloc] init];
        _AddressButton.frame = CGRectMake(ScreenWidth * 0.5, 95 * px, ScreenWidth * 0.5 - 100 * px, _birthdayButton.height);
        [_AddressButton setTitle:[NSString stringWithFormat:@"%@",[WYCAccountTool unarchiveprovince]] forState:UIControlStateNormal];
        [_AddressButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _AddressButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _AddressButton.titleLabel.font = _birthdayButton.titleLabel.font;
        [_AddressButton addTarget:self action:@selector(AddressButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _AddressButton;
}

/** 国家选择*/
- (UITextView *)SpecialityText {
    if (!_SpecialityText) {
        _SpecialityText = [[UITextView alloc] init];
        _SpecialityText.frame = CGRectMake( ScreenWidth / 3, 85 * px, ScreenWidth * 0.55, 80 * px);
        _SpecialityText.textColor = [UIColor whiteColor];
        _SpecialityText.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
        _SpecialityText.layer.backgroundColor = [[UIColor clearColor] CGColor];
        _SpecialityText.layer.borderColor = [[UIColor grayColor]CGColor];
        _SpecialityText.layer.borderWidth = 1.0;
        [_SpecialityText.layer setMasksToBounds:YES];
    }
    return _SpecialityText;
}


/** e分割*/
- (UIImageView *)FengeImg {
    if (!_FengeImg) {
        _FengeImg = [[UIImageView alloc] init];
        _FengeImg.frame = CGRectMake(80 * px, 299 * px, ScreenWidth - 160 * px, 1);
        
        //        _FengeImg.layer.cornerRadius = _photoImg.height * 0.5;
        _FengeImg.image = [UIImage imageNamed:@"line"];
    }
    return _FengeImg;
}
/** y头像*/
- (UIImageView *)photoImg {
    if (!_photoImg) {
        _photoImg = [[UIImageView alloc] init];
        _photoImg.frame = CGRectMake(ScreenWidth - 300 * px, 25 * px, 200 * px, 200 * px);
        _photoImg.layer.cornerRadius = _photoImg.height * 0.5;
        _photoImg.layer.masksToBounds = YES;
        _photoImg.userInteractionEnabled = YES;
        [_photoImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[WYCAccountTool unarchiveavatarUrl]]]];
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [_photoImg addGestureRecognizer:singleTap];
//        _photoImg.image = [UIImage imageNamed:@"上传头像"];
    }
    return _photoImg;
}
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
    
    UIAlertController *aler=[UIAlertController alertControllerWithTitle:@"更换头像" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    //从相机选取
    UIAlertAction *album = [UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController *picker=[[UIImagePickerController alloc]init];
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
        picker.allowsEditing = YES;
        picker.navigationBar.translucent = NO;
        picker.delegate = self;
        [self presentViewController:picker animated:YES completion:nil];
    }];
    
    //从相机选取
    UIAlertAction *camera=[UIAlertAction actionWithTitle:@"相机拍摄" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UIImagePickerController *picker=[[UIImagePickerController alloc]init];
        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes=[UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
        picker.allowsEditing=YES;
        picker.delegate = self;
        [self presentViewController:picker animated:YES completion:nil];
        
    }];
    
    UIAlertAction *cancl=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [aler addAction:cancl];
    [aler addAction:album];
    [aler addAction:camera];
    [self presentViewController:aler animated:YES completion:nil];
}

//选取图片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *image1=[info objectForKey:UIImagePickerControllerEditedImage];
    _photoImg.image = image1;
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    NSData *imageData = UIImageJPEGRepresentation(image1, 0.00001);
    
    NSString *encodedImageStr = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
    NSDictionary * params = @{@"file":encodedImageStr};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html",@"Type-Text",@"Content-Type", nil];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //发送网络请求(请求方式为POST)
    WYCLog(@"---%@",params);
    [manager POST:MSuploadAvatarUrl parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        
        NSString *fileName = [NSString stringWithFormat:@"%@.png",[formatter stringFromDate:[NSDate date]]];
        
        [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/png"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        WYCLog(@"-----------%@",responseObject);
        if (CodeStr) {
            self.URLStr = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"url"]];
        }else{
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        WYCLog(@"-----------%@",error);
    }];
    
    
}

/** 姓名*/
- (UITextField *)NameTextField {
    if (!_NameTextField) {
        _NameTextField = [[UITextField alloc] init];
        _NameTextField.frame = CGRectMake(ScreenWidth - 600 * px, 25 * px, 500 * px, 100 * px);
        _NameTextField.text = [WYCAccountTool unarchiveuserName];
        _NameTextField.placeholder = @"请输入昵称";
        [_NameTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [_NameTextField setValue:[UIFont systemFontOfSize:SYRealValue(28 / 2)] forKeyPath:@"_placeholderLabel.font"];
        _NameTextField.textColor = [UIColor whiteColor];
        _NameTextField.textAlignment = NSTextAlignmentRight;
    }
    return _NameTextField;
}

/** cell标题*/
- (NSArray *)titleArr {
    if (!_titleArr) {
        _titleArr = @[@"昵称", @"头像", @"性别", @"身高", @"生日", @"国籍", @"籍贯"];
    }
    return _titleArr;
}

/** 性别*/
- (NSArray *)sexArray {
    if (!_sexArray) {
        _sexArray = @[@"男", @"女"];
    }
    return _sexArray;
}

- (void)AddressButtonClick{
    
    [FYLCityPickView showPickViewWithComplete:^(NSArray *arr) {
        
        NSString *str =  [self replaceUnicode:[NSString stringWithFormat:@"%@%@",arr[0],arr[1]]];
        [_AddressButton setTitle:str forState:UIControlStateNormal];
        
    } withProvince:@"北京" withCity:@"北京市" withTown:nil withThreeScroll:YES];
}
/**
 转码为中文
 
 @param TransformUnicodeString 转码前
 @return 转码后
 */
-(NSString*) replaceUnicode:(NSString*)TransformUnicodeString

{
    
    NSString*tepStr1 = [TransformUnicodeString stringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];
    NSString*tepStr2 = [tepStr1 stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];
    NSString*tepStr3 = [[@"\""  stringByAppendingString:tepStr2]stringByAppendingString:@"\""];
    NSData*tepData = [tepStr3  dataUsingEncoding:NSUTF8StringEncoding];
    NSString*axiba = [NSPropertyListSerialization propertyListWithData:tepData options:NSPropertyListMutableContainers format:NULL error:NULL];
    
    return  [axiba stringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];
    
}

- (void)showPickerView {
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"nationality-zh" ofType:@"json"];
    NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
    
    NSArray * arr = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    
    //    NSLog(@"%@",arr);
    NSMutableArray * listName = [NSMutableArray new];
    for (NSDictionary * dict in arr) {
        [listName addObject:dict[@"name"]];
        
    }
    WYCLog(@"----------%@",listName);
    zySheetPickerView *pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:listName andHeadTitle:@"" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
        [self.stateButton setTitle:choiceString forState:UIControlStateNormal];
        [pickerView dismissPicker];
    }];
    [pickerView show];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectText:(NSString *)text {
    
    [self.stateButton setTitle:text forState:UIControlStateNormal];
}


- (void)GFAddressPickerCancleAction
{
    [self.pickerView removeFromSuperview];
}

- (void)GFAddressPickerWithProvince:(NSString *)province
                               city:(NSString *)city area:(NSString *)area
{
    [self.pickerView removeFromSuperview];
    
    [_AddressButton setTitle:[NSString stringWithFormat:@"%@ %@",province,city] forState:UIControlStateNormal];
    
    NSLog(@"%@  %@",province,city);
}
- (void)createNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"个人信息编辑";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
@end
